const fs = require('fs');
const path = require('path');

// 读取 package.json 文件
const packageJsonPath = path.resolve(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const env = process.argv[2];
let versionParts = packageJson.version.split('.');
if (env == 'dev') {
    versionParts = packageJson.dev_version.split('.');
}
// 分割版本号，并增加补丁版本号
versionParts[versionParts.length - 1] = parseInt(versionParts[versionParts.length - 1]) + 1;
if (env == 'dev') {
    packageJson.dev_version = versionParts.join('.');
} else {
    packageJson.version = versionParts.join('.');
}

// 写回 package.json 文件
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

console.log(`Version updated to ${packageJson.version}`);
